$(document).ready(function(){
	
	$("#modifyUser").val(username);
	
	//获取当前父亲Id
	var src = tl_config.his_url;
	var i = src.indexOf('?');
	if(i!=-1){
		var id = src.substring(i+4);	
        $.ajax({
        	url:server_url+'/rest/HelpCenterInfo/selectHelpCenterInfoById.do?ran='+Math.random()+ '&token=' + token,
        	type:'get',
        	data:{id:id},
        	success:function(data){
        		if(data.retCode==='0000'){        			
        			$("#id").val(data.data.id);
        			$("#parentId").val(data.data.parentId);
        			$("p#parentTitle").text(data.data.parentTitle);
        			$("#title").val(data.data.title);        			
        			$("#sort").val(data.data.sort);
        			ue.ready(function(){         			
        				ue.setContent(data.data.content);
        			});
        		}
        	}
        });
	}	
	
	//表单验证
	var validate = $("#fromEditHelpCenterChildInfo").validate({		   
		rules:{					
			title:{
				  required:true,
			      remote: { 
	                   url: server_url+'/rest/HelpCenterInfo/checkTitleEdit.do?timestamp='+Math.random()+ '&token=' + token,
	                   type: "post",
	                   dataType: "json", 
	                   data: {	id: function() { return $("#id").val();},	                	        
	                	        title: function() { return $("#title").val();},
	                	        parentId: function() { return $("#parentId").val();}
	                         } 
	               },
	               stringMaxLength:30
			}
		},
		messages:{				
			  title:{
			           required:"该值不能为空！",
                       remote:"该标题名已存在，请重新输入!",
                       stringMaxLength:"最多能输入30个字符！"
                   }
		},
		submitHandler:function(){
			sub();
		},
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo ( element.parent() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.parent() );
			else if ( element.is("input[name=captcha]") )
				error.appendTo ( element.parent() );
			else
				error.insertAfter(element);
		},
		validClass : 'rightValidate',
	    success: function(label) {
		   label.html("&nbsp;").text(" ") ;
	    }
 });	

	
});


//提交
function sub(){
	if($("#fromEditHelpCenterChildInfo").valid()){
		$.ajax({
			url:server_url+'/rest/HelpCenterInfo/HelpCenterInfoEdit.do?ran='+Math.random()+ '&token=' + token,
			type:'post',
			data:$("#fromEditHelpCenterChildInfo").serialize(),
			success:function(data){
				easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose : 2000});
				back();
			}
		});
	}
}


function back(){
	var url="getHelpCenterChildListPage.do?ran="+Math.random();
	tl_config.loadToWorkArea(url);
}

function submitCommit(){
	$("#fromEditHelpCenterChildInfo").submit();
}
